package datasv.collegeQuery_datasv;

import java.util.Date;
import data.datafactory.DatabaseOperator;
import po.TeacherPO;
import resultmessage.CollegeQueryRM;

public class AddTeacher {
	public static void main(String[] args) {
		System.out.println(new AddTeacher().addTeacher("001",new TeacherPO("001132023", "test.t", "001", 2013, new Date(2013,11,27)),"001132002"));
		System.out.println("datasv addTeacher successfully");
	}
	public CollegeQueryRM addTeacher(String collegeID,TeacherPO po,String teacherID){
		return addInSql(collegeID, po, teacherID);
	}
	private CollegeQueryRM addInSql(String collegeID,TeacherPO po ,String teacherID){
		DatabaseOperator op=new DatabaseOperator("college"+collegeID);
		if(!op.ifDatabaseExist()){
			return CollegeQueryRM.COLLEGE_NOT_EXIT;
		}
		if(op.ifIDExist("teacher_list", po.getTeacherID())){
			return CollegeQueryRM.TEACHERID_EXIST;
		}
		String[] colName=op.getColumnName("teacher_list");
		String[][] m=new String[colName.length][colName.length];
		for (int i = 0; i < colName.length; i++) {
			m[i][0]=colName[i];
		}
		m[0][1]=po.getTeacherID();
		m[1][1]=po.getName();
		m[2][1]=Integer.toString(po.getBirthday().getYear())+"/"+Integer.toString(po.getBirthday().getMonth())+"/"+Integer.toString(po.getBirthday().getDate());// birthday
		m[3][1]=po.getCollegeID();
		m[4][1]=Integer.toString(po.getWorkStartYear());
		if(op.addOneRow(m, "teacher_list")){
			return CollegeQueryRM.SUCCESS;
		}
		return CollegeQueryRM.TEACHERID_EXIST;
	}
}
